package net.droiding.utils.map;

import java.util.ArrayList;

import net.droiding.activity.ProviderActivity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.widget.Toast;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class AvailabilityOverlay extends ItemizedOverlay<OverlayItem> {

	private ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
	private Context ctx = null;
	
	public AvailabilityOverlay(Context ctx, Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
		this.ctx = ctx;
	}

	public void addOverlay(OverlayItem item) {
		items.add(item);
		populate();
	}
	
	public void clear() {
		items.clear();
		populate();
	}
	public void addAll(ArrayList<OverlayItem> collection) {
		items.addAll(collection);
		populate();
	}
	
	@Override
	protected OverlayItem createItem(int i) {
		return items.get(i);
	}

	@Override
	public int size() {
		return items.size();
	}
	
	@Override
	protected boolean onTap(int index) {
		OverlayItem item = items.get(index);
		
		showDialog(item.getTitle(), item.getSnippet());
//		Toast.makeText(this.ctx, item.getSnippet(), Toast.LENGTH_LONG).show();
		return true;
	}
	private void showDialog(String title, String message) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this.ctx);
		builder.setMessage(message)
		       .setCancelable(false)
		       .setTitle(title)
		       .setPositiveButton("Update", new DialogInterface.OnClickListener() {
		           public void onClick(DialogInterface dialog, int id) {
		        	   dialog.cancel();
		        	   
		           }
		       })
		       .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
		           public void onClick(DialogInterface dialog, int id) {
		        	   dialog.cancel();
		           }
		       });
		AlertDialog alert = builder.create();
		alert.show();

	}	
}
